package com.inwavetech.os.util.entityfields;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.inwavetech.os.R;
import com.inwavetech.os.entity.Os;
import com.inwavetech.os.util.field.BigDecimalField;
import com.inwavetech.os.util.field.EnumField;
import com.inwavetech.os.util.field.FieldsCollection;
import com.inwavetech.os.util.field.PtBrDecimalFormat;
import com.inwavetech.os.util.field.TextField;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by jgskin on 2/17/14.
 */
public class FinishOsFields extends FieldsCollection {

    private Context context;

    public FinishOsFields(Context context, ViewGroup viewResource) {
        this.context = context;

        put("service_price", new BigDecimalField((TextView) viewResource.findViewById(R.id.price), new PtBrDecimalFormat()));
        put("service_justification", new TextField((TextView) viewResource.findViewById(R.id.price_detail)));
        put("closing_status", new EnumField((TextView) viewResource.findViewById(R.id.closing_status), buildEnumStringMap(Os.closingStatusResources)));
        put("name_responsible", new TextField((TextView) viewResource.findViewById(R.id.accountable)));
    }

    protected Map<Enum, String> buildEnumStringMap(Map<Enum, Integer> resourcesMap) {
        Map<Enum, String> enumStringMap = new HashMap<Enum, String>();

        for (Enum anEnum: resourcesMap.keySet()) {
            enumStringMap.put(anEnum, context.getString(resourcesMap.get(anEnum)));
        }

        return enumStringMap;
    }

}
